package com.qilu.pe.ui.activity;

import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import com.alipay.sdk.app.PayTask;
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.KeyboardUtils;
import com.flyco.dialog.listener.OnBtnClickL;
import com.flyco.dialog.widget.NormalDialog;
import com.google.gson.Gson;
import com.makeramen.roundedimageview.RoundedImageView;
import com.qilu.pe.R;
import com.qilu.pe.base.BaseResult2;
import com.qilu.pe.base.Config;
import com.qilu.pe.base.Global;
import com.qilu.pe.base.MyApp;
import com.qilu.pe.base.PayResult;
import com.qilu.pe.dao.bean.JsonBean;
import com.qilu.pe.dao.bean.MyProOrder;
import com.qilu.pe.dao.bean.ProductOrderDetails;
import com.qilu.pe.dao.bean.RefreshEvent;
import com.qilu.pe.dao.bean.UPayInfo;
import com.qilu.pe.dao.bean.WxPayInfo;
import com.qilu.pe.dao.http.APIRetrofit;
import com.qilu.pe.support.util.ActiviceCollector;
import com.qilu.pe.support.util.AlertUtil;
import com.qilu.pe.support.util.GetJsonDataUtil;
import com.qilu.pe.support.util.GlideUtil;
import com.qilu.pe.support.util.Logg;
import com.ruitu.arad.Arad;
import com.ruitu.arad.api.RxUtil;
import com.ruitu.arad.util.ToastUtils;
import com.tencent.mm.opensdk.modelpay.PayReq;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.unionpay.UPPayAssistEx;

import org.greenrobot.eventbus.EventBus;
import org.json.JSONArray;

import java.util.ArrayList;
import java.util.Map;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

/**
 * 新增 修改订单
 * 2020-12-02
 */
public class EditOrderActivity extends AppCompatActivity implements View.OnClickListener {

    private RoundedImageView iv_pro;
    private TextView tv_name, tv_desc, tv_price, tv_num, tv_score, tv_area, vTotal, tv_score_money;
    private EditText et_name, et_phone, et_addr;
    private TextView vRealPay;

    private String mId;
    private MyProOrder mOrder;
    private ProductOrderDetails mDetails;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_order_details);
        ActiviceCollector.addActivity(this);
        initView();
        initData();
    }

    public void initView() {
        findViewById(R.id.vBack).setOnClickListener(this);
        findViewById(R.id.tv_ok).setOnClickListener(this);
        iv_pro = findViewById(R.id.iv_pro);
        tv_name = findViewById(R.id.tv_name);
        tv_desc = findViewById(R.id.tv_desc);
        tv_price = findViewById(R.id.tv_price);
        tv_num = findViewById(R.id.tv_num);
        et_name = findViewById(R.id.et_name);
        et_phone = findViewById(R.id.et_phone);
        et_addr = findViewById(R.id.et_addr);
        tv_area = findViewById(R.id.tv_area);
        tv_area.setOnClickListener(this);
        vTotal = findViewById(R.id.vTotal);
        tv_score_money = findViewById(R.id.tv_score_money);
        vRealPay = findViewById(R.id.vRealPay);

        alert = new AlertDialog.Builder(this, R.style.Dialog_FS).create();
        alert2 = new AlertDialog.Builder(this, R.style.Dialog_FS).create();
        msgApi = WXAPIFactory.createWXAPI(this, null);
        msgApi.registerApp(Config.WX_APP_ID);
    }
    private AlertDialog alert2;// 弹窗
    private View alert_view2;
    public void initData() {
        mOrder = (MyProOrder) getIntent().getSerializableExtra("order");
        mId = getIntent().getStringExtra("orderId");

        APIRetrofit.getDefault().getProductOrderDetails(Global.HEADER, mId)
                .compose(RxUtil.<BaseResult2<ProductOrderDetails>>subIoObMain())
                .subscribe(new Consumer<BaseResult2<ProductOrderDetails>>() {
                    @Override
                    public void accept(BaseResult2<ProductOrderDetails> res) throws Exception {
                        if (res.isSuccess()) {
                            mDetails = res.getData();
                            tv_name.setText(mDetails.getName());
                            tv_desc.setText(mDetails.getIntro());
                            tv_price.setText("￥" + mDetails.getMoney());
                            tv_num.setText("x" + mDetails.getCount());
                            GlideUtil.loadImg(mDetails.getPicture(), iv_pro);

                            et_name.setText(mDetails.getUsername());
                            et_phone.setText(mDetails.getPhone());
                            tv_area.setText(mDetails.getArea());
                            et_addr.setText(mDetails.getAddress());

                            vTotal.setText(mDetails.getTotal());
                            tv_score_money.setText("￥" + mDetails.getSource_money());
                            vRealPay.setText("￥" + mDetails.getPrice());
                        } else {
                            ToastUtils.showShort(res.getMsg());
                        }
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        throwable.printStackTrace();
                        ToastUtils.showShort("网络请求失败");
                    }
                });
    }
    public void showDialog2() {// 弹窗
        alert2.show();
        alert_view2 = View.inflate(this, R.layout.layout_alert_com_alert, null);

        TextView tv_1 = alert_view2.findViewById(R.id.tv_1);
        TextView tv_2 = alert_view2.findViewById(R.id.tv_2);
        TextView tv_title = alert_view2.findViewById(R.id.tv_title);
        tv_1.setText("继续支付");
        tv_2.setText("确认离开");
        tv_title.setText("您的订单未支付，请尽快完成支付。");
        tv_1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alert2.dismiss();
                showDialog();
            }
        });
        tv_2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alert2.dismiss();
                finish();
            }
        });

        AlertUtil.setAlertCenterStyle(alert2.getWindow(), alert_view2, this);
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.vBack:
                finish();
                break;
            case R.id.tv_area:
                KeyboardUtils.hideSoftInput(this);
                initJsonData();
                ShowPickerView();
                break;
            case R.id.tv_ok:
                if (TextUtils.isEmpty(et_name.getText().toString().trim())) {
                    ToastUtils.showShort("请输入收货人姓名");
                    return;
                }
                if (TextUtils.isEmpty(et_phone.getText().toString().trim())) {
                    ToastUtils.showShort("请输入收货人手机");
                    return;
                }
                if (TextUtils.isEmpty(tv_area.getText().toString().trim())) {
                    ToastUtils.showShort("请选择收货人城市");
                    return;
                }
                if (TextUtils.isEmpty(et_addr.getText().toString().trim())) {
                    ToastUtils.showShort("请输入收货人地址");
                    return;
                }
                submitOrder();
                break;
        }
    }

    private void submitOrder() {
//        if (!et_name.getText().toString().trim().equals(mDetails.getUsername()) || !et_phone.getText().toString().trim().equals(mDetails.getPhone()) ||
//                !et_addr.getText().toString().trim().equals(mDetails.getAddress()) || !tv_area.getText().equals(mDetails.getArea())) {
            APIRetrofit.getDefault().editProductOrder(Global.HEADER, mDetails.getId(), et_name.getText().toString().trim(), et_phone.getText().toString().trim(),
                    tv_area.getText().toString(), et_addr.getText().toString().trim())
                    .compose(RxUtil.<BaseResult2>subIoObMain())
                    .subscribe(new Consumer<BaseResult2>() {
                        @Override
                        public void accept(BaseResult2 res) throws Exception {
                            if (res.isSuccess()) {
//                                ToastUtils.showShort("修改成功");
                                showDialog();
                            } else {
                                ToastUtils.showShort(res.getMsg());
                            }
                        }
                    }, new Consumer<Throwable>() {
                        @Override
                        public void accept(Throwable throwable) throws Exception {
                            throwable.printStackTrace();
                            ToastUtils.showShort("网络请求失败");
                        }
                    });
//        } else {
//            super.onBackPressed();
//        }
    }

    private ArrayList<JsonBean> options1Items = new ArrayList<>();
    private ArrayList<ArrayList<String>> options2Items = new ArrayList<>();
    private ArrayList<ArrayList<ArrayList<String>>> options3Items = new ArrayList<>();

    private void initJsonData() {//解析数据
//         * 注意：assets 目录下的Json文件仅供参考，实际使用可自行替换文件
//         * 关键逻辑在于循环体
        String JsonData = new GetJsonDataUtil().getJson(this, "city.json");//获取assets目录下的json文件数据
        ArrayList<JsonBean> jsonBean = parseData(JsonData);//用Gson 转成实体

//         * 添加省份数据
//         * 注意：如果是添加的JavaBean实体，则实体类需要实现 IPickerViewData 接口，
//         * PickerView会通过getPickerViewText方法获取字符串显示出来。
        options1Items = jsonBean;

        for (int i = 0; i < jsonBean.size(); i++) {//遍历省份
            ArrayList<String> CityList = new ArrayList<>();//该省的城市列表（第二级）
            ArrayList<ArrayList<String>> Province_AreaList = new ArrayList<>();//该省的所有地区列表（第三极）

            for (int c = 0; c < jsonBean.get(i).getCityList().size(); c++) {//遍历该省份的所有城市
                String CityName = jsonBean.get(i).getCityList().get(c).getName();
                CityList.add(CityName);//添加城市

                ArrayList<String> City_AreaList = new ArrayList<>();//该城市的所有地区列表

                //如果无地区数据，建议添加空字符串，防止数据为null 导致三个选项长度不匹配造成崩溃
                if (jsonBean.get(i).getCityList().get(c).getAreaList() == null || jsonBean.get(i).getCityList().get(c).getAreaList().size() == 0) {
                    City_AreaList.add("");
                } else {
                    for (int d = 0; d < jsonBean.get(i).getCityList().get(c).getAreaList().size(); d++) {//该城市对应地区所有数据
                        String AreaName = jsonBean.get(i).getCityList().get(c).getAreaList().get(d).getName();
                        City_AreaList.add(AreaName);//添加该城市所有地区数据
                    }
                }
                Province_AreaList.add(City_AreaList);//添加该省所有地区数据
            }
            //添加城市数据
            options2Items.add(CityList);
            //添加地区数据
            options3Items.add(Province_AreaList);
        }
    }

    public ArrayList<JsonBean> parseData(String result) {//Gson 解析
        ArrayList<JsonBean> detail = new ArrayList<>();
        try {
            JSONArray data = new JSONArray(result);
            Gson gson = new Gson();
            for (int i = 0; i < data.length(); i++) {
                JsonBean entity = gson.fromJson(data.optJSONObject(i).toString(), JsonBean.class);
                detail.add(entity);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return detail;
    }

    private void ShowPickerView() {// 弹出选择器
        OptionsPickerView pvOptions = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                //返回的分别是三个级别的选中位置
                String opt1tx = options1Items.size() > 0 ? options1Items.get(options1).getPickerViewText() : "";
                String opt2tx = options2Items.size() > 0 && options2Items.get(options1).size() > 0 ? options2Items.get(options1).get(options2) : "";
                String opt3tx = options2Items.size() > 0 && options3Items.get(options1).size() > 0 && options3Items.get(options1).get(options2).size() > 0 ? options3Items.get(options1).get(options2).get(options3) : "";

                String tx = opt1tx + opt2tx + opt3tx;
                String addr = tx;
                tv_area.setText(addr);
            }
        })
                .setTitleText("选择区域")
                .setDividerColor(Color.BLACK)
                .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
                .setContentTextSize(20)
                .build();
        pvOptions.setPicker(options1Items, options2Items, options3Items);//三级选择器
        pvOptions.show();
    }

    private AlertDialog alert;// 弹窗
    private View alert_view;
    String payType = "2";// 支付方式 1 微信,2 支付宝,3 银联支付,4 余额支付
    IWXAPI msgApi;

    public void showDialog() {// 弹窗界面
        alert.show();
        alert_view = View.inflate(this, R.layout.layout_alert_choose_pay_type, null);

        final RadioButton cb_ali = alert_view.findViewById(R.id.cb_ali);
        final RadioButton cb_wx = alert_view.findViewById(R.id.cb_wx);
        final RadioButton cb_union = alert_view.findViewById(R.id.cb_union);
        final RadioButton cb_balance = alert_view.findViewById(R.id.cb_balance);
        final TextView tv_balance0 = alert_view.findViewById(R.id.tv_balance0);// 显示余额数量

        RelativeLayout rl_ali = alert_view.findViewById(R.id.rl_ali);
        RelativeLayout rl_wechat = alert_view.findViewById(R.id.rl_wechat);
        RelativeLayout rl_union_pay = alert_view.findViewById(R.id.rl_union_pay);
        RelativeLayout rl_balance = alert_view.findViewById(R.id.rl_balance);

        tv_balance0.setText("余额支付 (¥" + Global.ORG_BALANCE + ")");
        alert.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialogInterface) {
                // 未支付返回提示信息：您的订单未支付，请尽快完成支付。
                // 继续支付按钮/确认离开按钮，点击确认离开跳转到我的订单列表页
                showDialog2();
            }
        });
        rl_ali.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                cb_ali.setChecked(true);
                cb_wx.setChecked(false);
                cb_union.setChecked(false);
                cb_balance.setChecked(false);
            }
        });
        cb_ali.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                cb_ali.setChecked(true);
                cb_wx.setChecked(false);
                cb_union.setChecked(false);
                cb_balance.setChecked(false);
            }
        });
        rl_wechat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                cb_ali.setChecked(false);
                cb_wx.setChecked(true);
                cb_union.setChecked(false);
                cb_balance.setChecked(false);
            }
        });
        cb_wx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                cb_ali.setChecked(false);
                cb_wx.setChecked(true);
                cb_union.setChecked(false);
                cb_balance.setChecked(false);
            }
        });
        rl_union_pay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                cb_ali.setChecked(false);
                cb_wx.setChecked(false);
                cb_union.setChecked(true);
                cb_balance.setChecked(false);
            }
        });
        cb_union.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                cb_ali.setChecked(false);
                cb_wx.setChecked(false);
                cb_union.setChecked(true);
                cb_balance.setChecked(false);
            }
        });
        rl_balance.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                cb_ali.setChecked(false);
                cb_wx.setChecked(false);
                cb_union.setChecked(false);
                cb_balance.setChecked(true);
            }
        });
        cb_balance.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                cb_ali.setChecked(false);
                cb_wx.setChecked(false);
                cb_union.setChecked(false);
                cb_balance.setChecked(true);
            }
        });

        alert_view.findViewById(R.id.tv_ok).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (cb_ali.isChecked()) {
                    payType = "2";
                } else if (cb_wx.isChecked()) {
                    payType = "1";
                } else if (cb_union.isChecked()) {
                    payType = "3";
                } else if (cb_balance.isChecked()) {
                    payType = "4";
                }
                if (cb_ali.isChecked()) {// 支付宝
                    reqAliPayInfo();
                } else if (cb_wx.isChecked()) {// 微信
                    reqWxPayInfo();
                } else if (cb_union.isChecked()) {// 银联
                    reqUPayPayInfo();
                } else if (cb_balance.isChecked()) {
                    reqBalancePayInfo();
                }
                alert.dismiss();
            }
        });

        AlertUtil.setAlertBottomInStyle(alert.getWindow(), alert_view, this);
    }

    private Disposable reqBalancePayInfo() {
        if (TextUtils.isEmpty(mDetails.getGood_num())) {
            ToastUtils.showShort("订单号异常");
            return null;
        }
        return APIRetrofit.getDefault().reqshopOrderPayBalance(Global.HEADER, mDetails.getGood_num(), payType)
                .compose(RxUtil.<BaseResult2>subIoObMain())
                .subscribe(new Consumer<BaseResult2>() {
                    @Override
                    public void accept(BaseResult2 baseResult2) throws Exception {
                        if (baseResult2.isSuccess()) {
                            paySuc();
                        } else {
                            ToastUtils.showShort(baseResult2.getMsg());
                        }
                        Logg.i("pay_data_balance = " + baseResult2.getData());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        throwable.printStackTrace();
                    }
                });
    }

    private Disposable reqUPayPayInfo() {
        if (TextUtils.isEmpty(mDetails.getGood_num())) {
            ToastUtils.showShort("订单号异常");
            return null;
        }
        return APIRetrofit.getDefault().reqshopOrderPayUpay(Global.HEADER, mDetails.getGood_num(), payType)
                .compose(RxUtil.<BaseResult2<UPayInfo>>subIoObMain())
                .subscribe(new Consumer<BaseResult2<UPayInfo>>() {
                    @Override
                    public void accept(BaseResult2<UPayInfo> baseResult2) throws Exception {
                        if (baseResult2.isSuccess()) {
                            uPay(baseResult2.getData().getTn());
                        } else {
                            ToastUtils.showShort(baseResult2.getMsg());
                        }
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        throwable.printStackTrace();
                    }
                });
    }

    private Disposable reqWxPayInfo() {
        if (TextUtils.isEmpty(mDetails.getGood_num())) {
            ToastUtils.showShort("订单号异常");
            return null;
        }
        return APIRetrofit.getDefault().reqshopOrderPayWx(Global.HEADER, mDetails.getGood_num(), payType)
                .compose(RxUtil.<BaseResult2<WxPayInfo>>subIoObMain())
                .subscribe(new Consumer<BaseResult2<WxPayInfo>>() {
                    @Override
                    public void accept(BaseResult2<WxPayInfo> baseResult2) throws Exception {
                        if (baseResult2.isSuccess()) {
                            wxPay(baseResult2);
                        } else {
                            ToastUtils.showShort(baseResult2.getMsg());
                        }
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        throwable.printStackTrace();
                        ToastUtils.showShort("获取微信支付信息错误");
                    }
                });
    }

    private Disposable reqAliPayInfo() {
        if (TextUtils.isEmpty(mDetails.getGood_num())) {
            ToastUtils.showShort("订单号异常");
            return null;
        }
        return APIRetrofit.getDefault().reqshopOrderPayAli(Global.HEADER, mDetails.getGood_num(), payType)
                .compose(RxUtil.<BaseResult2>subIoObMain())
                .subscribe(new Consumer<BaseResult2>() {
                    @Override
                    public void accept(BaseResult2 baseResult2) throws Exception {
                        if (baseResult2.isSuccess()) {
                            String orderInfo = (String) baseResult2.getData();
                            aliPay(orderInfo);
                        } else {
                            ToastUtils.showShort(baseResult2.getMsg());
                        }
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        throwable.printStackTrace();
                    }
                });
    }

    // 调起银联支付
    private void uPay(String tn) {
        UPPayAssistEx.startPay(EditOrderActivity.this, null, null, tn, MyApp.unionPayMode);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data == null) {
            return;
        }
        String str = data.getExtras().getString("pay_result");
        if (str.equalsIgnoreCase("success")) {
            paySuc();
        } else if (str.equalsIgnoreCase("fail")) {
            ToastUtils.showShort("银联支付失败");
        } else if (str.equalsIgnoreCase("cancel")) {
            ToastUtils.showShort("您取消了银联支付");
        }
    }

    // 调起微信支付
    private void wxPay(BaseResult2<WxPayInfo> baseResult2) {
        WxPayInfo wxPayInfo = baseResult2.getData();
        PayReq request = new PayReq();
        request.appId = wxPayInfo.getAppid();
        request.partnerId = wxPayInfo.getPartnerid();
        request.prepayId = wxPayInfo.getPrepayid();
        request.packageValue = "Sign=WXPay";
        request.nonceStr = wxPayInfo.getNoncestr();
        request.timeStamp = wxPayInfo.getTimestamp();
        request.sign = wxPayInfo.getSign();
        msgApi.sendReq(request);
    }

    // 调起支付宝支付
    private void aliPay(final String orderInfo) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                PayTask alipay = new PayTask(EditOrderActivity.this);
                Map<String, String> result = alipay.payV2(orderInfo, true);

                Message msg = new Message();
                msg.what = 20100851;
                msg.obj = result;
                mHandler.sendMessage(msg);
            }
        }).start();
    }

    @SuppressWarnings("all")
    private Handler mHandler = new Handler() {
        public void handleMessage(Message msg) {
            //返回码，标识支付状态，含义如下：9000——订单支付成功 8000——正在处理中 4000——订单支付失败 5000——重复请求 6001——用户中途取消 6002——网络连接出错
            if (msg.what == 20100851) {
                PayResult payResult = new PayResult((Map<String, String>) msg.obj);
                String payStatus = payResult.getResultStatus();
                if (TextUtils.equals(payStatus, "9000")) {// 判断resultStatus 为9000则代表支付成功
                    // 该笔订单是否真实支付成功，需要依赖服务端的异步通知。
                    ToastUtils.showShort("支付成功");
                    paySuc();

                } else if (TextUtils.equals(payStatus, "6001")) {
                    ToastUtils.showShort("取消支付");
                } else {
                    // 该笔订单真实的支付结果，需要依赖服务端的异步通知。
                    ToastUtils.showShort("支付失败");
                }
            }
        }
    };

    private void paySuc() {
        Intent intent=new Intent(EditOrderActivity.this, PaySuccessActivity.class);
        Bundle bundle = new Bundle();
        bundle.putString("from", "market");// 标识支付来源
        intent.putExtras(bundle);
        startActivity(intent);
        ActivityUtils.finishActivity(EditOrderActivity.class);
        finish();
        EventBus.getDefault().post(new RefreshEvent("refreshProductOrderList"));
    }

//    @Override
//    public void onBackPressed() {
//        if (!et_name.getText().toString().trim().equals(mDetails.getUsername()) || !et_phone.getText().toString().trim().equals(mDetails.getPhone()) ||
//                !et_addr.getText().toString().trim().equals(mDetails.getAddress()) || !tv_area.getText().equals(mDetails.getArea())) {
//            APIRetrofit.getDefault().editProductOrder(Global.HEADER, mDetails.getId(), et_name.getText().toString().trim(), et_phone.getText().toString().trim(),
//                    tv_area.getText().toString(), et_addr.getText().toString().trim())
//                    .compose(RxUtil.<BaseResult2>subIoObMain())
//                    .subscribe(new Consumer<BaseResult2>() {
//                        @Override
//                        public void accept(BaseResult2 res) throws Exception {
//                            if (res.isSuccess()) {
//                                ToastUtils.showShort("修改成功");
//                                EditOrderActivity.super.onBackPressed();
//                            } else {
//                                ToastUtils.showShort(res.getMsg());
//                            }
//                        }
//                    }, new Consumer<Throwable>() {
//                        @Override
//                        public void accept(Throwable throwable) throws Exception {
//                            throwable.printStackTrace();
//                            ToastUtils.showShort("网络请求失败");
//                        }
//                    });
//        } else {
//            super.onBackPressed();
//        }
//    }
}
